package com.yitao.cms.controller.banner;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedInput;
import com.skipper.base.bean.PagedOutput;

import com.yitao.client.dto.banner.BannerDto;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.service.banner.BannerCmsService;
import com.yitao.cms.utils.BaseUtils;
import com.yitao.cms.vo.banner.BannerInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 运营后台banner配置
 */
@RestController
@RequestMapping(value = "/cms/banner", produces = {"application/json"})
@Api(description = "运营后台banner配置相关", tags = {"cms-banner"})
public class BannerCmsController {
    @Autowired
    private BannerCmsService bannerCmsService;

    private BaseUtils baseUtils = BaseUtils.getInstance();

    @ApiOperation("新增banner图/广告图")
    @LogAnnotation(targetType = "bannerSave", remark = "新增banner图/广告图")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public DataOutput saveBanner(@RequestBody BannerInfoVo bannerInfoVo,
                                 HttpServletRequest request) {
        return bannerCmsService.saveBanner(bannerInfoVo, request);
    }

    /**
     * 查询banner集合
     */
    @ApiOperation("查询banner列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public PagedOutput<BannerInfoVo> getBannerList(@ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
                                                   @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize) {
        return bannerCmsService.getBannerListBean(new PagedInput(pageSize, pageNo), new BannerInfoVo());
    }

    /**
     * 查询banner详情
     */
    @ApiOperation("banner详情")
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public DataOutput<BannerInfoVo> getBannerInfo(@ApiParam(value = "bannerId") @RequestParam(value = "bannerId") Long bannerId) {
        return bannerCmsService.getBannerById(bannerId);
    }

    /**
     * 删除banner
     */
    @ApiOperation("删除banner")
    @LogAnnotation(targetType = "bannerDelete", remark = "删除banner")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public DataOutput deleteBannerById(@ApiParam(value = "bannerId") @RequestParam(value = "bannerId") Long bannerId, HttpServletRequest request) {
        return bannerCmsService.deleteBannerByBannerId(request, bannerId);
    }
}
